﻿using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

public class BallMovementJobSystem : JobComponentSystem
{
    [Unity.Burst.BurstCompile]
    public struct MovementJob : IJobProcessComponentData<Position, Rotation>
    {
        public int FrameCount;

        public void Execute(ref Position pos, ref Rotation rotation)
        {
            rotation.Value = Quaternion.AngleAxis(math.sin(FrameCount / Mathf.Rad2Deg) * 100, Vector3.up);
            pos.Value.y += Mathf.Sin(FrameCount / Mathf.Rad2Deg);
        }
    }

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        MovementJob job = new MovementJob();
        job.FrameCount = Time.frameCount;
        return job.Schedule(this, inputDeps);
    }
}